package com.jd.basic.service.impl;

import com.jd.basic.service.IBaiduAiAuditService;
import com.jd.basic.util.BaiduAuditUtils;
import org.springframework.stereotype.Service;

@Service
public class BaiduAiAuditServiceImpl implements IBaiduAiAuditService {

    @Override
    public Boolean textAudit(String auditText) {
        //文本审核
        return BaiduAuditUtils.TextCensor(auditText);
    }

    /*
     *  注意:resources是这样的格式：
     *  /group1/M00/00/02/CgAIC2KevEeAX2T4AAEUusLjqqk161.png,/group1/M00/00/02/CgAIC2KevEeAX2T4AAEUusLjqqk162.png
     *  需要判断是否为空，只有一张怎么处理，有多张怎么处理
     *  需要统一加前缀：http://123.207.27.208
     */
    @Override
    public Boolean imageAudit(String resources) {
        //图片审核
        Boolean result = true;
        if (resources != null){
            String[] arr = resources.split(",");
            for (String s: arr) {
                // 只要有一张图片审核失败就失败
                if (!BaiduAuditUtils.ImgCensor("http://123.207.27.208" + s)){
                    result = false;
                    break;
                }
            }
        }
        return result;
    }
}